package cn.ante.ymcc.utills;

import cn.ante.ymcc.dto.LoginJwtInfoDto;
import cn.ante.ymcc.util.AssertUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

public class LoginYmccContext {
    public static LoginJwtInfoDto getLoginContext(){
        SecurityContext context = SecurityContextHolder.getContext();
        AssertUtil.isTrue(context.getAuthentication().isAuthenticated(),"尚未登录");
        Object principal = context.getAuthentication().getPrincipal();
        return JSONObject.parseObject(principal.toString(),LoginJwtInfoDto.class);
    }
}